---
description: "Reference for Nitric's Go library - Store a new secret value"
---

# Go - Secret.Put()

<Note>
  This is reference documentation for the Nitric Go SDK. To learn about Secrets
  in Nitric start with the [Secrets docs](/secrets).
</Note>

Store a new secret value.

```go
import (
  "context"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/secrets"
)

func main() {
  secret := nitric.NewSecret("secret-name").Allow(secrets.SecretPut)

  versionName, err := secret.Put(context.TODO(), []byte("content"))
  if err != nil {
    return
  }

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
  <Property name="secret" required type="[]byte">
    The new secret value to store in the secrets manager.
  </Property>
</Properties>

### Notes

A new secret version is always created when calling `Put()`, the versions will automatically be provided a unique id. This behavior is dependent on the underlying secrets manager.

## Examples

### Store a new secret value

```go
import (
  "context"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/secrets"
)

func main() {
  secret := nitric.NewSecret("secret-name").Allow(secrets.SecretPut)

  versionName, err := secret.Put(context.TODO(), []byte("content"))
  if err != nil {
    return
  }

  nitric.Run()
}
```

### Get the id of a new secret version

Calling `put()` returns the ID of the new secret version. Storing the ID of the new version can be useful if you need to retrieve that specific value again in future using [secret.access()](./secret-access)

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/secrets"
)

func main() {
  secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)

  versionName, err := secret.Put(context.TODO(), []byte("content"))
  if err != nil {
    return
  }

  fmt.Println(versionName)

  nitric.Run()
}
```
